package anbserver;

import java.sql.Connection;
import java.sql.DriverManager;

public class ConnectDB {

    private String serverName = "localhost\\SQLEXPRESS";
    private String databaseName = "ANB";
    private String user = "sa";
    private String pass = "sa";
    private Connection con = null;

    //ket noi qua driver sql server
    public  Connection getConnection() {
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection("jdbc:sqlserver:// " + serverName + " ;Database= " + databaseName, user, pass);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return con;
    }

    //ket noi qua bridge JDBCODBC
    public Connection getConnectionODBC() {
        //dang ky su dung driver
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");       
            String url = "jdbc:odbc:" + databaseName;
            con = DriverManager.getConnection(url, user, pass);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return con;
    }
}
